########################  字典 dict    
### 1.构造  键 值  key : value   # 键值唯一
# person_dict = {'name':'Bob', 'age':35}
# person_dict = dict(name='Bob', age = 35)
# pairs = [('name', 'Bob'), ('age', 35)]
# person_dict = dict(pairs)
# ### 2.访问
# name = person_dict['name']
# name = person_dict.get('name')
# ### 3.添加/修改
# person_dict['city'] = 'Beijing'
# ### 4.删除
# #del person_dict['city']
# city_person = person_dict.pop('city')  ##返回删除值
# ### 5. 视图   #自动更新 
# key_view = person_dict.keys()
# value_view = person_dict.values()
# items_view = person_dict.items()
# ### 6. 访问
# for key_member in person_dict.keys():
#     print(key_member)
# for key_mem, value_mem in person_dict.items():
#     pass
# ### 7. 合并
# person2 = {'state': 'none'}
# merge_dict = person_dict | person2
########################  lambda匿名函数 lambda 参数 ： 表达式
# funcadd = lambda x,y : x+ y
# data = funcadd(12,25)
# getage2 = lambda s: s['age']
###########################  集合
# fruits = set()
# fruits.add('apple')
# fruits.remove('apple')
# fruits.discard('apple')


########################  list.sort(key, reverse)  key提取排序量函数。reverse默认升序
# students = [{'name': 'Alice', 'age': 20},  # 学生1：Alice，20岁
#     {'name': 'Bob', 'age': 18},    # 学生2：Bob，18岁
#     {'name': 'Charlie', 'age': 22} ]# 学生3：Charlie，22岁
# def getage(dict_mem):
#     return dict_mem['age']
# # students.sort(key=lambda s: s['age'])
# students.sort(key= getage ,reverse = True)

########################  sorted(parameters_list/dict, key ,reverse) 对list 字典 元组进行排序
# 排序函数  不改变原来list 字典 元组进行排序
########################  range(start, stop, step)

########################  动态规划
# 最优化问题 -> 子问题构成 ->
# 定义状态 -》状态转移 -》 正向/逆向求解 -》return 
# 状态转移 （递推）   (70) dp[i] = dp[i-1] + dp[i-2]

######################## listnode  #链表
# class ListNode:
#     def __init__(self, val = None , next = None):
#         self.val = val
#         self.next = next
#     def __str__(self):
#         return str(self.val)

# class RelativeNode:
#     def __init__(self):
#         self.head = ListNode()

#     def __str__(self):
#         """打印链表内容"""
#         items = []
#         current = self.head
#         while current:
#             items.append(str(current.val))
#             current = current.next
#         print(items)
#     def insert_at_begin(self, data):
#         """头部插入结点"""
#         newnode = ListNode(data)
#         if(self.head.val == None):
#             self.head = newnode
#             return     
#         newnode.next = self.head
#         self.head = newnode
#     def insert_at_end(self, data):
#         newnode = ListNode(data)
#         current = self.head
#         while current.next:
#             current = current.next
#         current.next = newnode
#     def insert_at_position(self, data, position):
#         """指定位置插入结点"""
#         if position == 0:
#             self.insert_at_begin(data)
#             return
#         else:
#             newnode = ListNode(data)
#             current = self.head
#             for i in range(position - 1):
#                 if(current.next == None):
#                     raise IndexError('超出链表范围！')
#                 current = current.next
                
#             newnode.next = current.next
#             current.next = newnode
#     def del_at_position(self, position):
#         """删除position位置元素"""
#         if(position ==0):
#             self.head = self.head.next
#         else:
#             current = self.head
#             for i in range(position - 1):
#                 current = current.next
#             current.next = current.next.next
# node1 = RelativeNode()
# node1.insert_at_begin(15)
# node1.__str__()
# node1.insert_at_begin(12)
# node1.__str__()
# node1.insert_at_end(10)
# node1.__str__()
# node1.insert_at_position(20, 3)
# node1.__str__()
# node1.del_at_position(3)
# node1.__str__()

############################  哈希表 hash  哈希表查找元素的时间复杂度为 o(1)
# 通过关键码的值直接进行访问的数据结构  用于快速查找元素，牺牲空间换取时间
# python dict() 就是hash

# 字典可以之间判断key值在不在
# num_set = set(list)  #元组也是


############################# 构建0列表  record = [0] * 26

############################## zip(a,b)  打包
# name = ['mym' , 'wph' , 'lzx']
# age = [21,23,20]
# person_zip = zip(name, age)   #zip class  [(),(),()]
# person_dict = dict(person_zip)

################################  str.split('signal') 
# import collections
# tm = collections.defaultdict(list)  # 使用 defaultdict 创建值为列表的字典，避免键不存在的 KeyError
# tm[''].append()


################################ 字符串
# 排序拼接
# s = 'holle'
# sorted_list = sorted(s)  # 生成新的排序列表
# print(sorted_list)  # 输出: ['e', 'h', 'l', 'l', 'o']
# sorted_str = ''.join(sorted_list)
################################  数字 转 字符串 str。选择格式
# num = 15.3
# str_= "{:.3f}".format(num) 
# str_= "{:03d}".format(int(num) )  #int 
## ord('A')     ASCII -- int
## chr(ord('A'))
################  
strr = 'aa a a'
strr = strr.upper()
strr = strr.lower()
splitstr = strr.split(' ',maxsplit=1)
############## 生成器表达式

sttrr =  ''.join(ch.lower() for ch in strr  if ch.isalnum)  #更高效的拼接方法

############################# 元组 tuple 与集合 set

############################## 双指针法/快慢指针 数组/字符串/链表

########################### 队列与栈 
# ##栈 stack 先入后出 LIFO
# import collections
# stack = collections.deque()# O(1)
# stack.append(1) #入栈
# stack.append(2) 
# OUT = stack.pop() #出栈

# ##队列 queue FIFO
# queue = collections.deque()
# queue.append(1)
# queue.append(2)
# out = queue.popleft()  #出队列

# import queue   # 线程安全队列
# queue_my = queue.Queue()
# queue_my.put(1)
# queue_my.get()  

# ##优先队列 
# import heapq
# heap = []
# heapq.heappush(heap, (3, 'a'))  # 入队 O(log n)
# heapq.heappush(heap, (3, 'b'))
# heapq.heappush(heap, (1, 'c'))
# top = heapq.heappop(heap)  # 出队 → 1（最小堆）

# ##线程安全 优先队列
# import queue
# heap = queue.PriorityQueue()
# heap.put((3, 'a'))
# heap.get()
# path = "/home///user/Documents/../Pictures"
# path_list = path.split('/')



############################  python match-case:
# status = 200
# match status:
#     case 200: strr =  "OK"
#     case 404: strr = "Not found"
#     case 500: strr =  "Server error"
#     case _: strr =  "Unknown status code"

################ eval()  #内置计算函数
# strrr = '3 + 5 '
# num = eval(strrr)

print('finished!')


#################################################################### 错误
# SyntaxError: invalid syntax  语法错误